const BaseController = require('../BaseController');

class UserController extends BaseController {
	// 查询产品
	async queryProduct() {
		const { ctx, app, service } = this;
		const body = ctx.request.body;
		const res = await service.admin.productService.queryProduct(body);
		this.ok(res);
	}
	// 创建产品
	async createProduct() {
		const { ctx, app, service } = this;
		const body = ctx.request.body;
		ctx.validate({
			productName: { type: 'string', required: true }
		});
		console.log('======body======', body);
		const res = await service.admin.productService.createProduct(body);
		this.ok(res);
    }
    
    // 更新产品
	async updateProduct() {
		const { ctx, app, service } = this;
		const body = ctx.request.body;
		ctx.validate({
			productName: { type: 'string', required: true }
		});
		const res = await service.admin.productService.updateProduct(body);
		this.ok(res);
	}

	// 删除产品
	async deleteProduct() {
		const { ctx, app, service } = this;
		const id = ctx.params.id;
		// 默认会对body校验
        ctx.validate({
			id: { type: 'string', required: true }
		}, { id });
		const res = await service.admin.productService.deleteProduct(id);
		this.ok(res);
	}
}

module.exports = UserController;
